<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>蜜雪冰城后台管理</title>
  <link rel="shortcut icon" href="../../favicon.ico">
  <!-- 引入样式 -->
  <link rel="stylesheet" href="../../plugins/element-ui/index.css" />
  <link rel="stylesheet" href="../../styles/common.css">
  <link rel="stylesheet" href="../../styles/login.css">
  <link rel="stylesheet" href="../../styles/icon/iconfont.css" />
  <style>
    .body{
      min-width: 1366px;
    }
  </style>
</head> 

<body>

  <div class="login" id="login-app" style="background-image: url(../../images/login/bc_1.jpg);background-size: 100%" >
    <div class="login-box" >

      <div style="height: 65px;width: 100%;top: 0;position: absolute;background-color: white"><span style="left: 20px;top: 10px;position: absolute"><img width="156px" src="../../images/icons/蜜雪logo.svg"></span><el-button type="text" @click="dialogVisible = true" style="border-radius: 0;font-size: 24px;right: 15%;line-height: 35px;background-color: #62a8f1;position: absolute;width: 90px;height: 65px;color:white;font-family: '微软雅黑 Light'">登录</el-button></div>
      <el-dialog

              :visible.sync="dialogVisible"
              width="30%"
              :before-close="handleClose">
        <div class="login-form">
          <el-form ref="loginForm" :model="loginForm" :rules="loginRules" >
            <div class="login-form-title">
              <p style="font-size: 28px;margin-bottom: 10px;color: black">&nbsp;欢迎登录</p>
            </div>
            <el-form-item prop="username">
              <el-input v-model="loginForm.username" type="text" auto-complete="off" placeholder="请输入用户名" maxlength="20"
              />
            </el-form-item>
            <el-form-item prop="password">

              <el-input v-model="loginForm.password" type="password" placeholder="密码"  maxlength="20"
                        @keyup.enter.native="handleLogin" />
            </el-form-item>
            <el-form-item style="width:100%;">
              <el-button class="login-btn" size="medium" type="primary" style="width:100%;"
                         @click.native.prevent="handleLogin">
                <span>点击登录</span>

              </el-button>
            </el-form-item>
          </el-form>
        </div>
      </el-dialog>

    </div>
  </div>

  <!-- 开发环境版本，包含了有帮助的命令行警告 -->
  <script src="../../plugins/vue/vue.js"></script>
  <!-- 引入组件库 -->
  <script src="../../plugins/element-ui/index.js"></script>
  <!-- 引入axios -->
  <script src="../../plugins/axios/axios.min.js"></script>
  <script src="../../js/request.js"></script>
  <script src="../../js/validate.js"></script>
  <script src="../../api/login.js"></script>

  <script>
    new Vue({
      el: '#login-app',
      data() {
        return {
          loginForm:{
            username: '',
            password: ''
          },
          dialogVisible: false,
          loading: false
        }
      },
      computed: {
        loginRules() {
          const validateUsername = (rule, value, callback) => {
            if (value.length < 1 ) {
              callback(new Error('请输入用户名'))
            } else {
              callback()
            }
          }
          const validatePassword = (rule, value, callback) => {
            if (value.length < 6) {
              callback(new Error('密码必须在6位以上'))
            } else {
              callback()
            }
          }
          return {
            'username': [{ 'validator': validateUsername, 'trigger': 'blur' }],
            'password': [{ 'validator': validatePassword, 'trigger': 'blur' }]
          }
        }
      },
      created() {
      },
      methods: {
        async handleLogin() {
          this.$refs.loginForm.validate(async (valid) => {
            if (valid) {
              this.loading = true
              let res = await loginApi(this.loginForm)
              if (String(res.code) === '1') {
                localStorage.setItem('userInfo',JSON.stringify(res.data))
                window.location.href= '../../index.html'
              } else {
                this.$message.error(res.msg)
                this.loading = false
              }
            }
          })
        }
      }
    })
  </script>
</body>

</html>
